package com.msb.mall.product.web;

import com.msb.mall.product.entity.CategoryEntity;
import com.msb.mall.product.service.CategoryService;
import com.msb.mall.product.vo.Catalog2VO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

/**
 * @Description
 * @Author liujianlin <157429758@qq.com>
 * @Version V1.0.0
 * @Since 1.0
 * @Date 2024/7/15
 */
@Controller
public class IndexController {

    @Autowired
    private CategoryService categoryService;

    @GetMapping({"/", "/index", "/index.html", "/home", "home.html"})
    public String index(Model model) {
        // 查询所有一级分类
        List<CategoryEntity> list = categoryService.getLeva1Category();
        model.addAttribute("categorys", list);

        return "index";
    }
    // static/index/json/catalog.json

    @ResponseBody
    @RequestMapping("/static/index/json/catalog.json")
    public Map<String, List<Catalog2VO>> getCatalog2JSON() {
        return categoryService.getCategory2JSON();
    }
}
